<?php
namespace app\index\controller;

use lib\Db;
use lib\Response;

class Index extends Common{

    /**
     * 首页
     * @return string
     * @throws \Exception
     */
    function index(){
        return $this->fetch();
    }

    //=================== ajax

    /**
     * 列表
     * @return array
     * @throws \Exception
     */
    function _list(){
        $page = $this->data['pageNum'] ? $this->data['pageNum'] : 1;
        $list = Db::name('diary d')
	        ->field('d.*, p.url, u.avatar, u.nickname, b.name as book_name')
	        ->join('diary_pic p', 'p.diary_id = d.id', 'left')
	        ->join('book b', 'd.book_id = b.id', 'left')
	        ->join('user u', 'd.uid = u.id', 'left')
	        ->order('d.id desc')
	        ->where(['b.open'=>'true'])
	        ->page($page, 15)
	        ->select();
        return Response::success('ok', $list);
    }

}